package fr.louloutes.lolshooter;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import fr.louloutes.lolshooter.engine.GameThread;

public class GameView extends SurfaceView implements SurfaceHolder.Callback
{

	GameThread t;

	@Override
	public boolean onTouchEvent( MotionEvent event )
	{
		int x = ( int ) event.getX();
		int y = ( int ) event.getY();

		t.player.setPosition( x, y - 100 );

		if ( event.getAction() == MotionEvent.ACTION_DOWN )
		{
			t.isFiring = true;
		}
		if ( event.getAction() == MotionEvent.ACTION_UP )
		{
			t.isFiring = false;
		}

		return true;
	}

	public GameView( Context context, AttributeSet attrs )
	{
		super( context, attrs );
		SurfaceHolder holder = getHolder();
		holder.addCallback( this );
	}

	@Override
	public void surfaceChanged( SurfaceHolder holder, int format, int width,
			int height )
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void surfaceCreated( SurfaceHolder holder )
	{
		t = new GameThread( holder, getResources() );
		t.start();
	}

	@Override
	public void surfaceDestroyed( SurfaceHolder holder )
	{
		t.end();

	}

}
